package com.whpost.api.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import cn.dev33.satoken.stp.StpUtil;
import com.whpost.api.utils.ApiUtils;
import com.whpost.service.entity.tools.ResultInfo;
import com.whpost.service.service.BaseServices;
import com.whpost.service.tools.ToolBean;
import jakarta.annotation.Resource;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

public class BaseController {

    private String perCode;

    private BaseServices baseServices;

    public void setPerCode(String perCode) {
        this.perCode = perCode;
    }

    public void setBaseServices(BaseServices baseServices) {
        this.baseServices = baseServices;
    }

    public BaseServices getBaseServices() {
        return baseServices;
    }

    public String getPerCode() {
        return perCode;
    }

    /**
     * 存盘
     * @return
     */
    @RequestMapping(value ="/save")
    public ResultInfo save(@RequestBody Map<String, Object> map){
        StpUtil.checkPermissionAnd(perCode+":add",perCode+":update");
        String loginId = ApiUtils.getLoginId();
        return baseServices.save(loginId,map);
    }

    /**
     * 删除
     * @return
     */
    @RequestMapping(value ="/del")
    public ResultInfo del(@RequestBody Map<String, Object> map){
        StpUtil.checkPermission(perCode+":del");
        String loginId = ApiUtils.getLoginId();
        return baseServices.del(loginId,map);
    }

    /**
     * 增改页面
     * @return
     */
    @RequestMapping(value ="/info")
    public ResultInfo info(@RequestBody Map<String, Object> map){
        StpUtil.checkPermissionAnd(perCode+":add",perCode+":update");
        String loginId = ApiUtils.getLoginId();
        return baseServices.info(loginId,map);
    }
    /**
     * 查询页面
     * @return
     */
    @RequestMapping(value ="/query")
    public ResultInfo query(@RequestBody Map<String, Object> map){
        StpUtil.checkPermission(perCode+":query");
        String loginId = ApiUtils.getLoginId();
        return baseServices.query(loginId,map);
    }
}
